//
// Created by Scave on 2024/9/26.
//

#ifndef TIEC_MACRO_H
#define TIEC_MACRO_H
#include <string>
#include <memory>
#include <mutex>
#include <functional>

/// lambda或函数签名检查（允许返回类型转换）
template <typename T, typename Ret, typename... Args>
constexpr bool is_lambda_or_func = std::is_invocable_r_v<Ret, T, Args...>;

/// lambda签名检查（允许返回类型转换）
template <typename T, typename Ret, typename... Args>
constexpr bool is_lambda_with_signature =
  std::is_class_v<T> && !std::is_function_v<T> && std::is_invocable_r_v<Ret, T, Args...>;

/// lambda签名检查（严格匹配返回类型）
template <typename T, typename Ret, typename... Args>
constexpr bool is_lambda_with_exact_signature =
  std::is_class_v<T> && !std::is_function_v<T> && std::is_invocable_v<T, Args...>
  && std::is_same_v<std::invoke_result_t<T, Args...>, Ret>;

/// lambda签名检查（仅检查参数类型，不检查返回类型）
template <typename T, typename... Args>
constexpr bool is_lambda_with_args =
  std::is_class_v<T> && !std::is_function_v<T> && std::is_invocable_v<T, Args...>;

#define NS_TIEC tiec

#define PTR std::shared_ptr
#define UPTR std::unique_ptr
#define WPTR std::weak_ptr
#define MAKE_PTR std::make_shared
#define MAKE_UPTR std::make_unique
#define MAKE_WPTR std::make_weak
#define LOCK_GUARD(mtx) std::lock_guard<std:mutex> __lock(mtx);
#define LOCK_SHARED(mtx) std::shared_lock __lock(mtx);
#define LOCK_UNIQUE(mtx) std::unique_lock __lock(mtx);
#define LOCK_SCOPED(...) std::scoped_lock  __lock(__VA_ARGS__);
#define FUNCTION std::function
#define VOID_FUNCTION(...) std::function<void(__VA_ARGS__)>
#define PAIR std::pair

#ifdef _WIN32
using String = std::string;
#else
using String = std::string;
#endif
using Int64 = int64_t;
using Int32 = int32_t;
#ifdef MACOS
#include <MacTypes.h>
#else
using UInt64 = uint64_t;
using UInt32 = uint32_t;
#endif

#define SAFE_DELETE_PTR(ptr) \
if (ptr != nullptr) {        \
  delete ptr;                \
}
#endif //TIEC_MACRO_H
